import React from 'react';
import { Switch, Redirect, Route } from 'react-router-dom'

const RouterView = (props) => {
  const Com = props.routes.filter(v => v.component)
  const Redir = props.routes.filter(v => v.redirect)
  return <Switch>
    {
      Com.map((item) => {
        return <Route key={item.path} path={item.path} render={props => {
          return <item.component {...props} routes={item.children}></item.component>
        }}></Route>
      })
    }
    {
      Redir.map((item) => {
        return <Redirect key={item.path} from={item.path} to={item.redirect}></Redirect>
      })
    }
  </Switch>
}

export default RouterView;
